<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <title>{{site['name']}}</title>
  {% include _/base_head.html %}
  <style>
    @media (max-width:680px) {
        .code, .cols, .toc_n, .note_n, .char_k, .updated_at { display: none; }
    }
  </style>
</head>

<body>
<div class="app">
  {% module TopNav('首页') %}
  <div class="container">
    <div class="text-right">
      <a data-toggle="modal" data-target="#newProjModal" class="btn btn-default">创建项目</a>
      <a data-toggle="modal" data-target="#importProjModal" class="btn btn-default">导入项目</a>
    </div>
    {% module Table(model, rows) %}
    <p class="gray text-right" style="opacity: .7"><small>v{{handler.app.version}} by <a href="https://github.com/rhcad/duidu" target="_blank">耀觉 GitHub</a></small></p>
  </div>
</div>
{% include modal/new_proj.html %}
{% include _/base_foot.html %}
</body>
<script>
  function onSubmitNewProj($modal) {
    const data = getModalData($modal, ['code', 'name', 'comment'], 'p')
    postApi('/proj/add', data, res => {
      window.location = res.redirect
    })
  }
  function importProj($modal) {
  const zipFile = $modal.find('input')[0].files[0]
  const formData = new FormData()

  if (!zipFile || !/\.z(ip|db)$/.test(zipFile.name)) {
    return
  }
  if (zipFile.size > (1024 * 1024 * 10)) {
    return showError('文件大小不能超过10MB')
  }
  formData.append('file', zipFile)
  postApi(`/proj/import/auto`, formData, res => {
    showSuccess('导入成功', `已导入 ${res.data.length} 个项目(${res.data[0].name})和相关经典。`, reloadPage)
  })
}
</script>
</html>